package com.hisan.waimaidao.myview;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;


//之定义View(练习)
public class PonitView extends View implements View.OnClickListener {
    private int count=1;
    private int mWidth;
    private int mHeight;

    public PonitView(Context context) {
        super(context);
    }

    public PonitView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public PonitView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }



    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        setOnClickListener(this);
        Paint paint=new Paint();
        paint.reset();
        //设置抗拒齿
        paint.setAntiAlias(true);
        paint.setColor(Color.RED);
        //画笔样式为空心时，设置空心画笔的宽度
        paint.setStrokeWidth(1);
        /**
         * 3种模式 STROKE：边缘填充
         * FILL:充满
         * FILL_AND_STROKE:2种结合
         */
        paint.setStyle(Paint.Style.FILL);
        //画线（画一条直线）
        // canvas.drawLine(0,0,100,100,paint);
        //共四个只开始的xy->结束的xy轴（画多条直线）用于折线图的绘制
        //        float[] floats={0,0,100,100,100,100,200,100,200,100,300,150};
        //        canvas.drawLines(floats,paint);
        //        /**
        //         *画圆 x轴 y轴
        //         */
        //        canvas.drawPoint(100,100,paint);
        //        float[] floats={200,200,300,300,400,400};
        //        canvas.drawPoints(floats,paint);
        //        //画圆弧
        //        /**
        //         * 四个属性 左侧x轴 顶部y轴 右侧x轴 底部y轴
        //         */
        RectF rectF=new RectF(250,100,500,350);
        Rect rect=new Rect(250,100,500,350);
        //太阳伞
//        /**
//         *  起始点 sweepAngle：绘制的角度
//         * boolean 是否显示圆心点
//         */
//        paint.setColor(Color.RED);
//        canvas.drawArc(rectF,0,45,true,paint);
//        paint.setColor(Color.WHITE);
//        canvas.drawArc(rectF,45,45,true,paint);
//        paint.setColor(Color.RED);
//        canvas.drawArc(rectF,90,45,true,paint);
//        paint.setColor(Color.WHITE);
//        canvas.drawArc(rectF,135,45,true,paint);
//        paint.setColor(Color.RED);
//        canvas.drawArc(rectF,180,45,true,paint);
//        paint.setColor(Color.WHITE);
//        canvas.drawArc(rectF,225,45,true,paint);
//        paint.setColor(Color.RED);
//        canvas.drawArc(rectF,270,45,true,paint);
//        paint.setColor(Color.WHITE);
//        canvas.drawArc(rectF,315,45,true,paint);
        //画图片
//       Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher);
//        canvas.drawBitmap(bitmap,0,0,paint);

        //画文字
        //        paint.setStrokeWidth(1);
        //        paint.setStyle(Paint.Style.FILL);
        //        paint.setTextSize(30);
        //        String data="这么熟悉的车技,莫非你是老司机。";
        //        //canvas.drawText(data,0,50,paint);
        //        Path path=new Path();
        //        //Path.Direction cv顺时针 ccv逆时针
        //        path.addCircle(200,200,70,Path.Direction.CW);
        //        canvas.drawTextOnPath(data,path,0,0,paint);
//        //画购物车右上角数量角标
//        //居中显示
//        canvas.drawCircle(getMeasuredWidth()/2,getMeasuredHeight()/2-100,100,paint);
//        String data=count+"";
//        Rect bunnds=new Rect();
//        paint.setTextSize(40);
//        //根据文字的宽度画出相应的矩阵
//        paint.getTextBounds(data,0,data.length(),bunnds);
//        paint.setStyle(Paint.Style.FILL);
//        Log.v("xxx",getMeasuredHeight()/2+"");
//        //居于外部矩形居中
//        canvas.drawText(data,getMeasuredWidth()/2-bunnds.width()/2-5,
//                getMeasuredWidth()/2+100+bunnds.height()/2,paint);




    }


    @Override
    public void onClick(View view) {
        count++;
        //同步刷新
        //invalidate();
        //异步刷新
        postInvalidate();
    }
}
